package com.jwds.digital.bios.business.core.infrastructure.dto.belt.assembler;

import com.jwds.digital.bios.business.core.infrastructure.dto.belt.BeltAnomalyInfoReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.belt.BeltAnomalyInfoRespVO;
import com.jwds.digital.bios.business.core.infrastructure.entity.belt.BeltAnomalyInfo;
import java.util.Objects;

/**
 * BeltAnomalyInfo DTO与Entity之间的相互转换
 *
 * @author 林柏云
 * @date 2024-10-24
 */
public class BeltAnomalyInfoAssembler {

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @return 实体对象
  */
  public static BeltAnomalyInfo dto2entity(BeltAnomalyInfoReqDTO dto)  {
    if (dto == null) {
      return null;
    }
    BeltAnomalyInfo entity = new BeltAnomalyInfo();
    entity.setBeltId(dto.getBeltId());
    entity.setRouteId(dto.getRouteId());
    entity.setTaskId(dto.getTaskId());
    entity.setResolved(dto.getResolved());
    entity.setAnomalyItem(dto.getAnomalyItem());
    entity.setSuggestion(dto.getSuggestion());
    return entity;
  }

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @param entity 原实体对象
  * @return 实体对象
  */
  public static BeltAnomalyInfo dto2entity(BeltAnomalyInfoReqDTO dto, BeltAnomalyInfo entity){
    if (dto == null) {
      return null;
    }
    if(Objects.nonNull(dto.getBeltId())) {
      entity.setBeltId(dto.getBeltId());
    }
    if(Objects.nonNull(dto.getRouteId())) {
      entity.setRouteId(dto.getRouteId());
    }
    if(Objects.nonNull(dto.getTaskId())) {
      entity.setTaskId(dto.getTaskId());
    }
    if(Objects.nonNull(dto.getResolved())) {
      entity.setResolved(dto.getResolved());
    }
    if(Objects.nonNull(dto.getAnomalyItem())) {
      entity.setAnomalyItem(dto.getAnomalyItem());
    }
    if(Objects.nonNull(dto.getSuggestion())) {
      entity.setSuggestion(dto.getSuggestion());
    }
    return entity;
  }

  /**
  * 将实体对象转换为传输对象
  *
  * @param entity 实体对象
  * @return 传输对象
  */
  public static BeltAnomalyInfoRespVO entity2dto(BeltAnomalyInfo entity) {
    if (entity == null) {
      return null;
    }
    BeltAnomalyInfoRespVO dto = new BeltAnomalyInfoRespVO();
    dto.setId(entity.getId());
    dto.setBeltId(entity.getBeltId());
    dto.setRouteId(entity.getRouteId());
    dto.setTaskId(entity.getTaskId());
    dto.setResolved(entity.getResolved());
    dto.setAnomalyItem(entity.getAnomalyItem());
    dto.setAnomalyDesc(entity.getAnomalyDesc());
    dto.setAnomalyTime(entity.getAnomalyTime());
    dto.setSuggestion(entity.getSuggestion());
    return dto;
  }

}
